local qingshi = fk.CreateSkill {
  name = "lingling__qingshi",
}

Fk:loadTranslationTable{
  ["lingling__qingshi"] = "倾势",
  [":lingling__qingshi"] = "出牌阶段限两次，你可以将所有牌当【决斗】使用，然后你获得受到伤害的角色所有牌，其摸两张牌。"..
  "当你使用牌被抵消后，你可以摸一张牌。",

  ["#lingling__qingshi"] = "倾势：将所有牌当【决斗】使用，然后获得受伤角色所有牌，其摸两张牌",
}

qingshi:addEffect("viewas", {
  anim_type = "offensive",
  prompt = "#lingling__qingshi",
  card_filter = Util.FalseFunc,
  view_as = function(self, player, cards)
    local card = Fk:cloneCard("duel")
    card:addSubcards(player:getCardIds("he"))
    return card
  end,
  after_use = function(self, player, use)
    local room = player.room
    if use.damageDealt then
      for _, p in ipairs(room:getAlivePlayers()) do
        if use.damageDealt[p] and not p.dead then
          if not player.dead then
            if p == player then
              if #player:getCardIds("e") > 0 then
                room:moveCardTo(p:getCardIds("e"), Card.PlayerHand, player, fk.ReasonPrey, qingshi.name, nil, false, player)
              end
            elseif not p:isNude() then
              room:moveCardTo(p:getCardIds("he"), Card.PlayerHand, player, fk.ReasonPrey, qingshi.name, nil, false, player)
            end
          end
          if not p.dead then
            p:drawCards(2, qingshi.name)
          end
        end
      end
    end
  end,
  enabled_at_play = function(self, player)
    return player:usedEffectTimes(qingshi.name, Player.HistoryPhase) < 2 and not player:isNude()
  end
})

qingshi:addEffect(fk.CardEffectCancelledOut, {
  anim_type = "drawcard",
  can_trigger = function (self, event, target, player, data)
    return target == player and player:hasSkill(qingshi.name)
  end,
  on_use = function (self, event, target, player, data)
    player:drawCards(1, qingshi.name)
  end,
})

qingshi:addAI(nil, "vs_skill")

return qingshi
